package utils;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import com.nsn.vs.sdm.util.regex.UtilRegex;

public class File {
	
	/**
	 * get the latest folder by the digit of the folder name
	 * @param dirList
	 * @return foldername
	 */
	public static String getLatestFolderByDigit(List<String> dirList)
	{
		
		if(dirList.size()==0){
			return null;
		}
		Map<String, Integer> filterFolder=new HashMap<String, Integer>();
		for (String folder: dirList){
			if (UtilRegex.filterDigital(folder)==null)
			{
				continue;
			}
			filterFolder.put(folder, UtilRegex.filterDigital(folder));
		}
		Collection<Integer> values = filterFolder.values();
		Integer tmp=Integer.valueOf(values.toArray()[0].toString());
		for (Integer value : values){
			if (tmp<value)
			{
				tmp=value;
			}
		}
		int mapsize = filterFolder.size();
		Iterator keyValuePairs1 = filterFolder.entrySet().iterator();
		for (int i = 0; i < mapsize; i++)
		{
		  Map.Entry entry = (Map.Entry) keyValuePairs1.next();
		  Object value = entry.getValue();
		  System.out.println(Integer.valueOf(value.toString()));
		  if (Integer.valueOf(value.toString()).compareTo(tmp)==0)
		  {
			  System.out.println("here");
			  return entry.getKey().toString();
		  }
		}
		return null;
			
	}
	public static void main(String []args){
		List<String> var=new ArrayList<String>();
		var.add("AV_BV7800");
		var.add("AV_BV8800");
		var.add("AV_BV7900");
		var.add("AV_BV");
		//System.out.println(getLatestFolderByDigit({"AV_BV7800","AV_BV7900","AV_BV8800","THIS"}));
		System.out.println(getLatestFolderByDigit(var));
	}
}
